package com.roc.web.timer;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;


import javax.annotation.Resource;

import org.springframework.stereotype.Component;


import com.roc.util.Constance;


@Component
public class TimerStart {
	private long delay=0;// 任务延迟执行的时间长度
	private long period=1000*60*60*24;//任务定时执行的周期,一天执行一次
		
	@Resource
	private ScheduleTask sckScheduleTask;
	
	
	public TimerStart(){}
	
	
	
	public void vick(){
		try{
			Timer timer=new Timer();
			timer.schedule(sckScheduleTask, getDelayTimes(), period); //生产	
		}catch(Exception e){
			e.printStackTrace();
			
		}
			
	}
	
	/**
	 * 定时器延时到7：30分执行
	 * @return
	 */
	private long getDelayTimes(){
		Calendar c=Calendar.getInstance();
		Date date=c.getTime();
		long times=c.getTimeInMillis();
	    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	   // System.out.println(sdf.format(date));
	    int hour=c.get(Calendar.HOUR_OF_DAY);
	    if(hour>1){
	    	c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH)+1);
	    	c.set(Calendar.HOUR_OF_DAY, 0);
	    	c.set(Calendar.MINUTE, 15);
	    	c.set(Calendar.SECOND, 0);
	    	c.set(Calendar.MILLISECOND, 0);
	    	long times_new=c.getTimeInMillis();
	    	return times_new-times;
	    	
	    }else{
	    	
	    	c.set(Calendar.HOUR_OF_DAY, 0);
	    	c.set(Calendar.MINUTE, 15);
	    	c.set(Calendar.SECOND, 0);
	    	c.set(Calendar.MILLISECOND, 0);
	    	long times_new=c.getTimeInMillis();
	    	return times_new-times;
	    }
	    
		
	}

	public long getDelay() {
		return delay;
	}

	public void setDelay(long delay) {
		this.delay = delay;
	}



	public long getPeriod() {
		return period;
	}



	public void setPeriod(long period) {
		this.period = period;
	}


public static void main(String[] args) {
	TimerStart t=new TimerStart();
	t.vick();
}
	
	

}
